package com.eshop.eshopmanagersystem.idal;

import com.eshop.eshopmanagersystem.model.BarcodeInfo;
import com.eshop.eshopmanagersystem.model.OrderBarcodesRelationshipInfo;
import com.eshop.eshopmanagersystem.model.OrderInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

/**
 * 接口层
 * 产品查询接口
 */

@Mapper
@Component
public interface IBarcodeDAL {
    /**
     * 根据条形码数值查询指定商品
     */
    @Select("select * from barcodes where barcode=#{barcode}")
    public BarcodeInfo getProductByBarcode(BarcodeInfo barcode);

    /**
     * 生成订单，插入数据
     * return 这里返回的是新增加的订单order_id
     * 方法：使用 @Options 注解
     */
    @Insert("insert into order_tb(user_id,order_code,order_pay,sum,total_price)values(#{user_id},#{order_code},#{order_pay}," +
            "#{sum},#{total_price})")
    @Options(useGeneratedKeys = true,keyProperty = "order_id",keyColumn = "order_id")
    public Integer addOrder(OrderInfo orderInfo);

    /**
     * 生成订单与产品关系表
     * 插入数据
     */
    @Insert("insert into order_barcodes_rel(order_id,id,price,count)values(#{order_id},#{id},#{price},#{count})")
    public Integer addOrderAndBarcodesRelation(OrderBarcodesRelationshipInfo obrs);
}
